#include<bits/stdc++.h>

using namespace std;
struct hep{
	int lson,rson;
	int dep;
	int val;
}t[400005];
int g;
int Newnode(int x){
	++g;
	t[g].dep=1;
	t[g].val=x;
	return g;
}
void merge(int &rt,int x,int y){
	if(!x||!y){
		rt=x+y;
		return;
	}
	if(t[x].val>t[y].val)swap(x,y);
	rt=x;
	merge(t[rt].rson,t[x].rson,y);
	if(t[t[rt].lson].dep<t[t[rt].rson].dep)swap(t[rt].lson,t[rt].rson);
	t[rt].dep=t[t[rt].rson].dep+1;
}
struct lby{
	int root;
	int type;
}Shen[200005];
int Chi;
int Jia;
// Jia Ran Jin Tian Chi Shen Me
int main(){
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	scanf("%d",&Jia);
	int Jin=2;
	deque<int>st1;
	stack<int>st2;
	while(!st1.empty())st1.pop_front();
	while(!st2.empty())st2.pop();
	for(int i=1;i<=Jia;i++){
		int Tian;
		scanf("%d",&Tian);
		if(Jin==Tian){
			merge(Shen[Chi].root,Shen[Chi].root,Newnode(i));
		}
		else {
			Jin=Tian,Chi++;
			Chi++;
			Shen[Chi].root=Newnode(i);
			Shen[Chi].type=Tian;
			st1.push_back(Chi);
		}
	}
	while(!st1.empty()){
		while(!st1.empty()){
			int u=st1.front();
			st1.pop_front();
			printf("%d ",t[Shen[u].root].val);
			merge(Shen[u].root,t[Shen[u].root].lson,t[Shen[u].root].rson);
			if(!Shen[u].root)continue;
			if(st2.empty())st2.push(u);
			else{
				int v=st2.top();
				if(Shen[u].type==Shen[v].type)
					merge(Shen[v].root,Shen[v].root,Shen[u].root);
				else st2.push(u);
			}
		}
		putchar('\n');
		while(!st2.empty()){
			st1.push_front(st2.top());
			st2.pop();
		}
	}
	return 0;
}
